<?php
namespace app\common\server;
use x\Xbase;
class Ordermtom extends Xbase{

    /**
     * 收益转余额
     * @param  [type] $user_id [description]
     * @param  [type] $money   [description]
     * @return [type]          [description]
     */
    public function sytoye($user_id,$money){
        $user = $this->db->find('user',$user_id);
        if ($user['money_sy']<$money) return $this->setError('余额不足！');

        $order_no = $this->com_order_no();
        $this->db->begin();
        $mysql = [];

        $fee = bcmul($money, sys('sytoye_fee'),2);
        $real_money = bcsub($money,$fee,2);
        $data = [
            'order_no' => $order_no,
            'user_id' => $user_id,
            'money_type' => 'money_sy',
            'shou_type' => 'money',
            'money' => $money,
            'fee' => $fee,
            'real_money' => $real_money,
            'create_time' => time()
        ];
        $mysql[] = $order_id = $this->db->insert('order_mtom',$data);

        $mysql[] = m('Userbill','xcom')->doit($data['order_no'], $data['user_id'], 207, 'order_mtom', $order_id,  $data['money'],$data['money_type'],'收益转出');
        $mysql[] = m('Userbill','xcom')->doit($data['order_no'], $data['user_id'], 107, 'order_mtom', $order_id,  $data['real_money'],$data['shou_type'],'收益转入');

        $rs = $this->db->end($mysql);
        if(!$rs){
            return $this->setError('转出失败');
        }else{
            return true;
        }
    }
   
}
